#!/usr/bin/perl 

use warnings;
use strict;

if ($#ARGV != 0) {
	print "Please input dev path\n";
	exit -1
}
print $ARGV[0];

print "Before unplug device:\n";
system("lsscsi");

my $line;
my @items;
my $item;
my $find = 0;

open(LSSCSI, "lsscsi |");
while (defined($line = <LSSCSI>)) {
	chomp($line);
	@items = split(/ /, $line);
	if ($items[$#items] eq $ARGV[0]) {
		@items[0] =~ /\[(.*)\]/;
		print("echo 1 > /sys/bus/scsi/devices/$1/delete\n");
		system("echo 1 > /sys/bus/scsi/devices/$1/delete");
		$find = 1;
	}
}
close(LSSCSI);

if ($find == 1) {
	print "After unplug device:\n";
	system("lsscsi");
} else {
	print "Can't find $ARGV[0]\n";
}

